package org.kia.activity;

import org.kia.activity.interfaces.BaseActivityInterface;
import org.kia.manager.KiaManager;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

/**
 * Base class for all of Kia's activities. <br/>
 * Used to control basic flow and common functionalities
 * 
 * @author Amir Lazarovich
 */
public abstract class KiaActivity<T extends KiaManager> extends Activity implements BaseActivityInterface {
	
	//////////////////////////////////////////////
	// Constants
	//////////////////////////////////////////////
	private static final String TAG = "BaseActivity";
	
	//////////////////////////////////////////////
	// Members
	//////////////////////////////////////////////
	protected T mManager;
	
	//////////////////////////////////////////////
	// Activity flow & initializers
	//////////////////////////////////////////////
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

	/**
	 * Initialization sequence
	 */
	private void init() {
		initMembers();
		initListeners();
		initManager();
		assert (mManager != null) : "Activity must have a manager";
	}

	/**
	 * Initialize all listeners
	 */
	protected void initListeners() {
		
	}

	/**
	 * Initialize all members
	 */
	protected void initMembers() {
		
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mManager.onActivityDestroy();
	}
	
	
	//////////////////////////////////////////////
	// Abstract
	//////////////////////////////////////////////
	
	/**
	 * Initialize manager
	 */
	abstract protected void initManager();
	
	
	//////////////////////////////////////////////
	// Overrides & Implementation
	//////////////////////////////////////////////
	
	@Override
	public Context getContext() {
		return this;
	}

}
